# -*- coding: utf-8 -*-
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext import db

from emof import core as EMOF
from emof import dumper
from emof import loader

from model import Model


class LoadAllTypes(webapp.RequestHandler):
    def get(self):
        m_id = self.request.get("m_id")
        
        model = Model.get(m_id)

        types = list()
        
        rep = loader.Loader().load(model.model_XMI)
        
        for pt in rep.PrimitiveType:
            types.append(pt)
        
        for enum in rep.Enumeration:
            types.append(enum)
        
        for clss in rep.Class:
            types.append(clss)

        template_values = {'types': types,
                           'id': id}
        
        path = os.path.join(os.getcwd(), 'xml/getTypes.xml')
        self.response.headers['Content-Type'] = 'application/xml'
        self.response.out.write(template.render(path, template_values))
        